    //
//  SettingPathVC_iPad.m
//  WRY
//
//  Created by zhong sckj on 10-12-14.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "SettingPathVC_iPad.h"
#import "RootVC_iPad.h"
#import "LoginVC_iPad.h"
#import "WebPath.h"
#import "AppDelegate_iPad.h"
#import "CommonJson.h"

@implementation SettingPathVC_iPad
@synthesize rootVc,loginVc;
@synthesize fromTag;




// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title=@"服务器地址设置";
	UIBarButtonItem *leftItem=[[UIBarButtonItem alloc]initWithTitle:@"取消" 
															  style:UIBarButtonItemStyleBordered 
															 target:self 
															 action:@selector(backPage:)];
	self.navigationItem.leftBarButtonItem=leftItem;
	
	UIBarButtonItem *rightItem=[[UIBarButtonItem alloc]initWithTitle:@"保存" 
															   style:UIBarButtonItemStyleBordered 
															  target:self 
															  action:@selector(saveAction:)];
	self.navigationItem.rightBarButtonItem=rightItem;
	[rightItem release];
	[leftItem release];
    
	
    textViewPath.layer.cornerRadius=8.0;
    textViewPath.text=[WebPath loginPath];
	
	
	
}
- (void)viewWillAppear:(BOOL)animated
{
	[super viewWillAppear:animated];
		
	
}
-(void)backPage:(id)sender
{
	if (fromTag==100) {
        [loginVc.popController dismissPopoverAnimated:YES];
    }
    else {
        [self.navigationController popViewControllerAnimated:YES];
    }

	
}


-(void)getSystemWebPath
{
    [self showLoading:0 centerY:0];
	
	[[CommonJson sharedInstance] requestToPath:textViewPath.text
									methodName:@"Search__SystemWebService"
									bodyString:@"" 
									 targetObj:self 
							  targetMethodName:@"eventForSearch__SystemWebService:" 
									notifiName:@"Search__SystemWebService"];
}
-(void)eventForSearch__SystemWebService:(NSNotification *)notification
{
    [self hideLoading];
    [[CommonJson sharedInstance]removeTarget:self notiName:[notification name]];
    
	NSObject *object = [notification object];
	if ([object isKindOfClass:[NSDictionary class]]) {
		NSDictionary *dict = (NSDictionary *)object;
		if ([[dict objectForKey:@"Status"] intValue]==1) {
			NSArray *dataarray=[dict objectForKey:@"Data"];
            if (![dataarray isKindOfClass:[NSNull class]]) {
                if ([dataarray count]>0) {
                     NSUserDefaults *SaveDefaults = [NSUserDefaults standardUserDefaults];
                     [SaveDefaults setObject:textViewPath.text forKey:@"WebService__SystemManage__Json"];
                    for (NSDictionary * dict in dataarray) {
                        NSString *webPathName=[dict objectForKey:@"WebServiceName"];
                        if ([webPathName isEqualToString:@"WebService__Enterprise__Json"]) {
                             [SaveDefaults setObject:[dict objectForKey:@"WebServiceUrl"] forKey:@"WebService__Enterprise__Json"];
                            break;
                        }
                        
                    }
                    [[AppDelegate_iPad currentDelegate] restartApplication];
                    
        
                }
              
            }
               }
}

}
    
-(void)saveAction:(id)sender
{
    
    //去获取所有地址
    [self getSystemWebPath];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Overriden to allow any orientation.
    return YES;
}


- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
	//[finishpathdelegate release];
	[loginVc release];
	[textViewPath release];
	[rootVc release];
    [super dealloc];
}


@end
